package invalidj2eebusinessservicedependency;

import org.eclipse.emf.ecore.EObject;

import org.eclipse.viatra2.emf.incquery.validation.runtime.Constraint;
import org.eclipse.viatra2.emf.incquery.validation.runtime.ValidationUtil;
import org.eclipse.viatra2.emf.incquery.runtime.api.impl.BaseGeneratedMatcherFactory;
import invalidj2eebusinessservicedependency.InvalidJ2eeBusinessServiceDependencyMatch;
import invalidj2eebusinessservicedependency.InvalidJ2eeBusinessServiceDependencyMatcherFactory;
import invalidj2eebusinessservicedependency.InvalidJ2eeBusinessServiceDependencyMatcher;

public class InvalidJ2eeBusinessServiceDependencyConstraint extends Constraint<InvalidJ2eeBusinessServiceDependencyMatch> {

	private InvalidJ2eeBusinessServiceDependencyMatcherFactory matcherFactory;

	public InvalidJ2eeBusinessServiceDependencyConstraint() {
		matcherFactory = new InvalidJ2eeBusinessServiceDependencyMatcherFactory();
	}

	@Override
	public String getMessage() {
		return "$j2eeService.name$ J2EE business service should not depend from $otherService.name$ business service, cause it is implemented with another technology!";
	}

	@Override
	public EObject getLocationObject(InvalidJ2eeBusinessServiceDependencyMatch signature) {
		Object location = signature.get("j2eeService");
		if(location instanceof EObject){
			return (EObject) location;
		}
		return null;
	}
	
	@Override
	public int getSeverity() {
		return ValidationUtil.getSeverity("error");
	}
	
	@Override
	public BaseGeneratedMatcherFactory<InvalidJ2eeBusinessServiceDependencyMatch, InvalidJ2eeBusinessServiceDependencyMatcher> getMatcherFactory() {
		return matcherFactory;
	}
}
